package com.dk.hi.core;

import java.util.List;

import com.dk.hi.core.exceptions.team.FullTeamException;
import com.dk.hi.core.exceptions.team.NoSuchHeroInTeamException;
import com.dk.hi.core.exceptions.team.NotEnoughMoneyException;
import com.drakulo.hi.logic.actors.Hero;

/**
 * Represents the player team. A team is composed by 1 to 4 heroes.
 */
public class Team {
	public static final int TEAM_MAX_HEROES = 4;
	/**
	 * The heroes in the team
	 */
	private static List<Hero> heroes;

	/**
	 * Amount of money
	 */
	private static int money;

	/**
	 * Adds a hero to the player's team
	 * 
	 * @param hero
	 *            - the hero to add
	 * @throws FullTeamException
	 *             is thrown if the team has already 4 heroes
	 */
	public static void addHero(Hero hero) throws FullTeamException {
		if (heroes.size() == TEAM_MAX_HEROES) {
			// Oops, the team is full!
			throw new FullTeamException();
		}
		heroes.add(hero);
	}

	/**
	 * Adds money
	 * 
	 * @param delta
	 *            the amount of money to add
	 */
	public static void addMoney(int delta) {
		Team.money += delta;
	}

	/**
	 * @return a List containing all heroes of the team
	 */
	public static List<Hero> getHeroes() {
		return heroes;
	}

	/**
	 * @return the team's money
	 */
	public static int getMoney() {
		return money;
	}

	/**
	 * Initializes team's money
	 * 
	 * @param money
	 *            - the amount of money
	 */
	public static void initMoney(int money) {
		Team.money = money;
	}

	/**
	 * Removes a hero from the team
	 * 
	 * @param hero
	 *            - the hero to remove
	 * @throws NoSuchHeroInTeamException
	 *             is thrown if the hero is not in the team
	 */
	public static void removeHero(Hero hero) throws NoSuchHeroInTeamException {
		if (!heroes.contains(hero)) {
			throw new NoSuchHeroInTeamException();
		}
		heroes.remove(hero);
	}

	/**
	 * Removes money
	 * 
	 * @param delta
	 *            the amount of money to remove
	 * @throws NotEnoughMoneyException
	 *             thrown if the team has not enough money
	 */
	public static void removeMoney(int delta) throws NotEnoughMoneyException {
		if (Team.money < delta) {
			throw new NotEnoughMoneyException();
		}
		Team.money -= delta;
	}
}
